﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics.Contracts;

namespace RPGMapRevealer
{
    /// <summary>
    /// the size, offset, and border width of the map
    /// </summary>
    public class GridConfig
    {
        private int _tileWidth = 32;
        private int _tileHeight = 32;
        private int _tileOffsetX = 0;
        private int _tileOffsetY = 0;
        private int _tileBorder = 0;

        /// <summary>
        /// The width in pixels of the tiles on this Map
        /// </summary>
        public int TileWidth
        {
            get
            {
                Contract.Ensures(Contract.Result<int>() > 0);
                return _tileWidth;
            }
            set
            {
                Contract.Requires(value > 0);
                _tileWidth = value;
            }
        }

        /// <summary>
        /// The height in pixels of the tiles on this Map
        /// </summary>
        public int TileHeight
        {
            get
            {
                Contract.Ensures(Contract.Result<int>() > 0);
                return _tileHeight;
            }
            set
            {
                Contract.Requires(value > 0);
                _tileHeight = value;
            }
        }

        /// <summary>
        /// The offset in pixels from the left edge of the image where the first tile starts
        /// </summary>
        public int TileOffsetX
        {
            get
            {
                Contract.Ensures(Contract.Result<int>() >= 0);
                return _tileOffsetX;
            }
            set
            {
                Contract.Requires(value >= 0);
                _tileOffsetX = value;
            }
        }
        /// <summary>
        /// The offset in pixels from the top edge of the image where the first tile starts
        /// </summary>
        public int TileOffsetY
        {
            get
            {
                Contract.Ensures(Contract.Result<int>() >= 0);
                return _tileOffsetY;
            }
            set
            {
                Contract.Requires(value >= 0);
                _tileOffsetY = value;
            }
        }

        /// <summary>
        /// The number of pixels around the edge of each tile which should be "ignored" when checking to see if the tile is empty or not.
        /// </summary>
        public int TileBorder
        {
            get
            {
                Contract.Ensures(Contract.Result<int>() >= 0);
                return _tileBorder;
            }
            set
            {
                Contract.Requires(value >= 0);
                _tileBorder = value;
            }
        }

        [ContractInvariantMethod]
        private void InvariantMethod()
        {
            Contract.Invariant(_tileHeight > 0);
            Contract.Invariant(_tileWidth > 0);
            Contract.Invariant(_tileOffsetX >= 0);
            Contract.Invariant(_tileOffsetY >= 0);
            Contract.Invariant(_tileBorder >= 0);
        }
    }
}
